package 代码coding题OR模拟题;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author aodre , QQ : 480029069
 * @date 2022/12/6 13:31
 */
public class leetcode1805coding {


    public int solution(String word){
            Set<String> set = new HashSet<>();

            for(int i = 0;i < word.length();i++){
                if(word.charAt(i) == '0' && (i + 1 == word.length() || !judge(word.charAt(i + 1))))
                    set.add("0");
                if(judge(word.charAt(i)) && word.charAt(i) != '0'){
                    int j = i;
                    while(j < word.length() && judge(word.charAt(j)) ){
                        j++;
                    }
                    String substring = word.substring(i, j);
//                    if(substring.charAt(0) != '0' || substring.length() == 1)
                    set.add(substring);
                    i = j;
                }
            }
            return set.size();
    }
    public boolean judge(char ch){
        if(ch <= '9' && ch >= '0')
            return true;
        return false;
    }

    public static void main(String[] args) {
        String word = "leet1234code234";
//        String word = "035985750011523523129774573439111590559325";
        int solution = new leetcode1805coding().solution(word);
        String[] split = word.split("[^0-9]");
        System.out.println(split.length);
        System.out.println(Arrays.toString(split)
        );
        System.out.println(solution);
    }


    /*
        秀了 一手 正则表达式！
        其实下面的算法效率 不是很高，
        主要体现的就是 ，对 语言的 api 的熟练程度！
     */
    public int numDifferentIntegers(String word) {
        HashSet<String> set = new HashSet<>();
        for (String s : word.split("[^0-9]")) {
            if (!s.isEmpty()) {
                set.add(s.replaceAll("^0+", ""));
            }
        }
        return set.size();
    }
}
